woocommerce apply coupon programmatically

129

function wc_ninja_apply_coupon( $coupon_code ) {
	if ( 'test_code' === $coupon_code ) {
		$product_id = 99;
		WC()->cart->add_to_cart( $product_id );
	}
}
add_action( 'woocommerce_applied_coupon', 'wc_ninja_apply_coupon' );

Comments

Submit
0 Comments